package com.avic.rong.goodsSort.adapter.secondListAdapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.goodsSort.bean.GoodsSortDrawerBean;

import java.util.List;

/**
 * Created by Chenjiaxin on 2019/7/15 20:22
 * E-Mail Address：16601203965@163.com
 */
public class GoodsSortBzDrawerDownTimeRvAdapter extends RecyclerView.Adapter<GoodsSortBzDrawerDownTimeRvAdapter.GoodsSortBzDrawerDownTimeViewHolder> {
    private Context context;
    private List<GoodsSortDrawerBean> gnList;
    private LayoutInflater inflater;
    private int itemCount = 4;
    private View view;
    public GoodsSortBzDrawerDownTimeListener goodsSortBzDrawerDownTimeListener;

    public GoodsSortBzDrawerDownTimeListener getGoodsSortBzDrawerDownTimeListener() {
        return goodsSortBzDrawerDownTimeListener;
    }

    public void setGoodsSortBzDrawerDownTimeListener(GoodsSortBzDrawerDownTimeListener goodsSortBzDrawerDownTimeListener) {
        this.goodsSortBzDrawerDownTimeListener = goodsSortBzDrawerDownTimeListener;
    }

    public GoodsSortBzDrawerDownTimeRvAdapter(Context context, List<GoodsSortDrawerBean> gnList) {
        this.context = context;
        this.gnList = gnList;
        inflater = LayoutInflater.from(context);
        Log.e("cjx","DownTimeList:"+gnList.size());
    }


    @NonNull
    @Override
    public GoodsSortBzDrawerDownTimeViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        view = inflater.inflate(R.layout.view_goods_rv_item1, viewGroup, false);
        return new GoodsSortBzDrawerDownTimeViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull GoodsSortBzDrawerDownTimeViewHolder holder, int i) {
        holder.tv.setText(gnList.get(i).getS());
        holder.tv.setSelected(gnList.get(i).isFlag());
        holder.tv.setClickable(gnList.get(i).isClickable());
        holder.tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goodsSortBzDrawerDownTimeListener.onDownTime(i);
            }
        });
    }

    @Override
    public int getItemCount() {
        if (gnList.size() > 4) {
            return itemCount;
        } else {
            return gnList.size();
        }
    }
//
//    class GoodsBzTabRvViewHolder extends RecyclerView.ViewHolder{
//        RecyclerView rv;
//        public GoodsBzTabRvViewHolder(@NonNull View itemView) {
//            super(itemView);
//            rv = itemView.findViewById(R.id.goods_Bz_Rv1);
//        }
//    }

    class GoodsSortBzDrawerDownTimeViewHolder extends RecyclerView.ViewHolder {
        TextView tv;

        //        ImageView img;
        public GoodsSortBzDrawerDownTimeViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.goods_Item_tv1);
//            img = itemView.findViewById(R.id.goods_Bz_SelectorImg);
        }
    }

    public void addItemNums(int num) {
        itemCount = num;
    }
    public interface GoodsSortBzDrawerDownTimeListener{
        void onDownTime(int index);
    }
}
